<template> 
	<view>
		<view class="exanpleBaner">
			<image src="/static/images/banner1.png"></image>
		</view>
		<view class="exanpleBody" :style="'height:' + wh + 'px'">
			<view class="exanpleList">
				<scroll-view @scrolltolower="uploadMissioc" :style="'height:' + wh + 'px'" scroll-y="true" class="scroll">
					<view @click="goGoodDetail(item.product_id)" v-for="(item,index) in hotList" :key="index" class="exanpleItem">
						<view class="itemLeft">
							<image class="shopImg" :src="item.image"></image>
							<view class="shopOrder">
								<image src="/static/images/ranking.png"></image>
								<view class="orderNum">{{ index + 1 }}</view>
							</view>
						</view>
						<view class="itemRight">
							<view class="itemTitle">{{ item.store_name }}</view>
							<view class="itemNum">实时销量：{{ item.sales }}件</view>
							<view class="itemPrice">
								<text>￥{{ item.price }}</text>
								<text>￥{{ item.ot_price }}</text>
								<text class='shopCart iconfont icon-gouwuche1'></text>
								<!-- <image src="/static/images/shop-car.png"></image> -->
							</view>
						</view>
					</view>
					<view v-if="isover"class="over_line">----- 我也是有底线的 ------</view>
					<view v-if="!hotList.length" class="notAvailable">暂无榜单商品~</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				wh: '', // 当前屏幕可用的高度
				hotList:[],
				pagenum: 1, // 页码值
				pagesize: 20, // 每页显示多少条数据
				total: '',
				isover: false, // 判断是否到底部，给用户提示
				isloading: false // 判断数据是否在加载中
			};
		},
		onLoad() {
			// 获取设备的高度
			let that = this
			uni.getSystemInfo({
			    success: function (res) {
					that.wh = res.windowHeight - 138
			    }
			});
			that.getProductHot()
		},
		methods:{
			// 获取榜单
			getProductHot() {
				// 正在加载下页数据
				this.isloading = true;
				this.$api.getProductHot({
					page: this.pagenum,
					limit: this.pagesize
				},res => {
					this.total = res.data.count;
					this.hotList = [...this.hotList, ...res.data.list];
					// 没有在加载下页数据
					this.isloading = false;
				})
			},
			goGoodDetail(id) {
				uni.navigateTo({
					url: `/pages/goods_details/index?id=${id}`
				});
			},
			// 滚动到底部加载任务数据
			uploadMissioc() {
				if (!this.hotList.length) {
					return;
				}
				// 判断当前是否正在请求数据中
				if (this.isloading) {
					return;
				}
				if (this.pagesize * this.pagenum >= this.total) {
					this.isover = true;
					return;
				}
				this.pagenum++;
				this.getProductHot();
			},
		}
	}
</script>

<style lang="less">
.exanpleBaner {
	height: 277rpx;
	image {
		width: 100%;
		height: 100%;
	}
}

.exanpleBody {
	background-color: #FDCDB8;
	overflow: hidden;
	.exanpleList {
		width: 703rpx;
		// height: 100%;
		margin: 20rpx auto 0;
		background-color: #F4EFEE;
		padding-top: 20rpx;
		.scroll {
		overflow: hidden;
		.exanpleItem {
			display: flex;
			align-items: center;
			background-color: #FFFFFF;
			padding: 20rpx;
			margin-bottom: 20rpx;
			.itemLeft {
				position: relative;
				width: 182rpx;
				height: 182rpx;
				margin-right: 30rpx;
				.shopImg {
					width: 100%;
					height: 100%;
				}
				.shopOrder {
					position: absolute;
					top: -20rpx;
					left: 15rpx;
					width: 38rpx;
					height: 75rpx;
					image {
						width: 100%;
						height: 100%;
					}
					.orderNum {
						position: absolute;
						bottom: 10rpx;
						left: 50%;
						transform: translateX(-50%);
						font-size: 22rpx;
						color: #FAF9F9;
					}
				}
			}
			.itemRight {
					flex: 1;
					font-size: 27rpx;
					color: #070606;
					padding-top: 10rpx;
				.itemNum {
					width: 310rpx;
					height: 50rpx;
					font-size: 22rpx;
					color: #EF4520;
					background: linear-gradient(90deg, #FDD4C6 0%, #FFF3E3 100%);
					line-height: 50rpx;
					margin: 20rpx 0;
					padding-left: 10rpx;
				}
				.itemPrice {
					position: relative;
					text:nth-child(2) {
						font-size: 18rpx;
						text-decoration: line-through;
						color: #74706E;
						margin-left: 10rpx;
					}
					.shopCart {
						position: absolute;
						top: -10rpx;
						right: -10rpx;
						width: 43rpx;
						height: 43rpx;
					}
				}
			}
		}
		.notAvailable {
			width: 100%;
			height: 150rpx;
			text-align: center;
			line-height: 200rpx;
			font-size: 24rpx;
			color: #666;
		}
		.over_line {
			text-align: center;
			background-color: #F5F5F5;
			font-size: 26rpx;
			color: #999;
			padding: 20rpx 0;
		}
	}
	}
}
</style>
